<!-- BEGIN PAGE HEADER-->
<?php $this->load->view('partials/breadcrumb.tpl',  Array('_NO_IOSS_NEW'=>'1'))?>
<!-- END PAGE HEADER-->
<!-- BEGIN PAGE CONTENT-->
<script type="text/javascript">
function defConfirm(url){
	if(!confirm("确定要删除吗？")){
		return false;
	}
	window.location.href = url;
	return true;
}
$(document).ready(function(){
	$("#reset").click(function(){
		$("select").val('');
		$("input[type='text']").val('');
	});

	
});

function request_ingame_amount(row_id){
	//ajax post请求给定id用户的余额信息
	$('#a_'+row_id).hide();
	
	$.post("<?=site_url($thisModule.$thisController.'/postRequestAmountInGame/')?>",{user_id:row_id},function(ret){
		var retObj = $.parseJSON(ret);
		if(retObj.code < 0){
			alert(retObj.message);
			return;
		}
		//请求余额成功
		var ingame_amount = retObj.amount;
		var top_span = $('#ingame_amount_'+row_id);
		top_span.show();
		top_span.find('span').html(ingame_amount);
		var input_amount = top_span.find('input');
		top_span.find('button').click(function(){
			var set_amount = parseFloat(input_amount.val());
			var old_amount = parseFloat(ingame_amount);
			if(set_amount>old_amount){
				alert("数量变动不能大于原来值！");
				return;
			}
			top_span.hide();
			input_amount.val('');
			var withdraw_amount = old_amount-set_amount;
			withdraw_amount = withdraw_amount.toFixed(2);
			$.post("<?=site_url($thisModule.$thisController.'/postWithdraw/')?>",{user_id:row_id,withdraw_amount:withdraw_amount,ingame_amount:old_amount},function(result){
				var resultObj = $.parseJSON(result);
				alert(resultObj.message);
				$('#a_'+row_id).show();
			});
		});
		
	});
	
}
</script>
<div class="row">
	<div class="col-md-12">
		<!-- Begin: life time stats -->
		<div class="portlet">

			<?=form_open('', Array('class'=>'form-inline', 'role'=>'form'))?>
				<?=search_form_input('id',filterValue('id'),'用户编号', 'class="form-control input-medium"');?>
				<?=search_form_input('account',filterValue('account'),'用户账号', 'class="form-control input-medium"');?>
				<?=search_form_dropdown('status',Array(''=>'选择状态...', '1'=>'普通用户', '0'=>'禁用'),filterValue('status'),'状态', 'class="form-control input-medium"');?>
				<button type="button" class="btn default" id="reset">重置条件</button>
				<button type="submit" class="btn green about_search">搜索 <i class="fa fa-search"></i></button>
			<?=form_close()?>

			<div class="portlet-body">
				<div class="row">
					<div class="col-md-12">
						<div class="table-scrollable">
							<table class="table table-hover table-bordered table-striped">
								<thead>
								<tr>
									<th width="10%">用户编号</th>				
									<th width="10%">用户账号</th>
									<th width="10%">最后登录时间</th>
									<th width="60%">平台数量</th>
									<th width="10%">状态</th>
								</tr>
								</thead>
								<tbody>
								<?php  foreach ($list as $item){	?>
									<tr>
										<td><?=$item->id?></td>
										<td>										
												<?=htmlspecialchars($item->account)?>
										</td>
										
										<td><?=date('Y-m-d H:i:s',$item->login_time)?></td>
										<td>
											<a id="a_<?=$item->id?>" href="javascript:request_ingame_amount('<?=$item->id?>');">请求平台数量</a>&nbsp;&nbsp;
											<span id="ingame_amount_<?=$item->id?>" style="display:none;">
												<span style="color:green;"></span>&nbsp;
												<input type="text" placeholder="输入修改后数量"/>&nbsp;
												<button>确定修改</button>
											</span>
										</td>
										<td>
											<?=($item->status == 0 ? '<span class="label label-danger status_icons label_status_icons">禁用</span>' : '<span class="label label-success status_icons label_status_icons">启用</span>')?>
										</td>
									</tr>
								<?php }?>
								</tbody>
							</table>
						</div>
					</div>
				</div>
				<div class="row">
					<div class="col-md-12 text-right">
						<?=$pagination?>
					</div>
				</div>
			</div>
		</div>
		<!-- End: life time stats -->
	</div>
</div>

<!-- END PAGE CONTENT-->
